import logging
import os

from selenium import webdriver
from selenium.common import WebDriverException, NoSuchElementException
from selenium.webdriver.common.by import By


# ts_url=os.getenv('base_url')
driver = webdriver.Chrome()
# driver.get(ts_url)
driver.get('file:///C:/Users/jing/Desktop/07-1%20%E7%A7%BB%E5%8A%A8%20%E6%B5%8B%E8%AF%95%E7%B3%BB%20%E9%AB%986%E3%80%8A%E4%BC%81%E4%B8%9A%E7%BA%A7%E6%A6%82%E5%BF%B5%E5%88%B0%E4%BA%A4%E4%BB%98%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%E3%80%8B%E7%AC%AC3%E5%91%A8%20%E6%8A%80%E8%83%BD%E8%AF%95%E9%A2%98/%E5%9B%BE%E4%B9%A6%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.html')
driver.implicitly_wait(5)
driver.maximize_window()
try:
    logging.info("登录")
    # 用户名
    username = driver.find_element(By.ID, 'username').send_keys('admin')
    # 密码
    password = driver.find_element(By.ID, 'password').send_keys('123456')
    # 点击登录
    login = driver.find_element(By.XPATH, '//*[@id="loginForm"]/button')
except NoSuchElementException as e:
    print(e)
    logging.info("用户名或者密码错误")
except WebDriverException as e:
    print(e)
    logging.info("网络层连接异常")
except TimeoutError as e:
    print(e)
    logging.info("网络超时")
